package com.mrwang.example.nio.part20191027;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileChangeTest {

    public static void main(String[] args) {
        File file = new File("/Users/wanghanchao/Desktop/2019_tech.rtf");
        File targetFile =new File("/Users/wanghanchao/Desktop/mac_key_auth1.txt");


        try {
            FileInputStream is = new FileInputStream ( file );
            FileOutputStream os = new FileOutputStream ( targetFile );
            FileChannel inp = is.getChannel();
            FileChannel out = os.getChannel();
            ByteBuffer bb = ByteBuffer.allocate(1024);
            while (true){
                bb.clear();
                int read = inp.read(bb);
                if(read==-1){
                    break;
                }

                bb.flip();

                out.write(bb);
            }
            is.close();
            os.close();


        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally {

        }

    }
}
